package com.itedge.solutionmanager.service.processhelper;

import org.activiti.engine.impl.context.Context;
import org.springframework.beans.factory.annotation.Autowired;

import com.itedge.infrastructure.service.domain.IProcessEntityService;
import com.itedge.infrastructure.stereotype.ProcessHelper;
import com.itedge.solutionmanager.domain.impl.Solution;
import com.itedge.solutionmanager.enumeration.SolutionPhase;

@ProcessHelper
public class SolutionProcessHelper {
	
	@Autowired
	IProcessEntityService<Solution> solutionService; 
	
    public boolean isRejected() {
    	String currentProcId = Context.getExecutionContext().getProcessInstance().getProcessInstanceId();
        Solution linkedSolution = solutionService.findEntityByProcessId(currentProcId);    
        if (SolutionPhase.REJECTED.equals(linkedSolution.getPhase())) {
    	    return true;
        } else {
        	return false;
        }
    }
    
    public boolean isCompleted() {
    	String currentProcId = Context.getExecutionContext().getProcessInstance().getProcessInstanceId();
    	Solution linkedSolution = solutionService.findEntityByProcessId(currentProcId);    
        if (SolutionPhase.REJECTED.equals(linkedSolution.getPhase()) || SolutionPhase.FINISHED.equals(linkedSolution.getPhase())) {
    	    return true;
        } else {
        	return false;
        }
    }	

}
